package Solution.problem083.RemoveDuplicatesFromSortedList;

import common.ListNode;
import org.junit.Test;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/06/17 09:56
 */
public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null){
            return head;
        }
        ListNode resualt=head;
        int preValue=head.val;
        while (head.next!=null){
            if(head.next.val==preValue){
                head.next=head.next.next;
            }else{
                preValue=head.next.val;
                head=head.next;
            }
        }
        return resualt;
    }

    @Test
    public void test() {
        //1->2->3->4->5
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(1);
        ListNode listNode3 = new ListNode(1);
        ListNode listNode4 = new ListNode(3);
        ListNode listNode5 = new ListNode(4);
        ListNode listNode6 = new ListNode(4);
        ListNode listNode7 = new ListNode(5);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;
        listNode4.next = listNode5;
        listNode5.next = listNode6;
        listNode6.next = listNode7;
        ListNode result = deleteDuplicates(listNode1);
        System.out.println(result.val);
    }
}
